package cn.yuanqiao.archive.webservice.cconfig;

import cn.yuanqiao.archive.webservice.service.ArchiveWebService;
import cn.yuanqiao.archive.webservice.service.CqbcWebservice;
import cn.yuanqiao.archive.webservice.service.impl.ArchiveWebServiceImpl;
import cn.yuanqiao.archive.webservice.service.impl.CqbcWebserviceImpl;
import cn.yuanqiao.archive.webservice.service.impl.receiveFeedbackWebServiceImpl;
import cn.yuanqiao.archive.webservice.service.receiveFeedbackWebService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class WebServiceConfig {

    @Bean(name = "cxfServlet")  // 注入servlet bean name不能dispatcherServlet ,否则会覆盖dispatcherServlet
    public ServletRegistrationBean<CXFServlet> cxfServlet() {
        return new ServletRegistrationBean<CXFServlet>(new CXFServlet(), "/webservice/*");
    }

    @Bean
    public ArchiveWebService archiveWebService(){
        return new ArchiveWebServiceImpl();
    }
    @Bean
    public receiveFeedbackWebService receiveFeedbackWebService(){
        return new receiveFeedbackWebServiceImpl();
    }
    @Bean
    public CqbcWebservice cqbcWebservice(){
        return new CqbcWebserviceImpl();
    }


    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    @Qualifier("identifier1")
    public Endpoint endpoint() {
        // 参数二，是SEI实现类对象
        EndpointImpl endpoint = new EndpointImpl(this.springBus(), this.archiveWebService());
        // 发布服务
        endpoint.publish("/archiveWebService");
        return endpoint;
    }

    @Bean
    @Qualifier("identifier2")
    public Endpoint endpoint2() {
        // 参数二，是SEI实现类对象
        EndpointImpl endpoint = new EndpointImpl(this.springBus(), this.receiveFeedbackWebService());
        // 发布服务
        endpoint.publish("/receiveFeedbackWebService");
        return endpoint;
    }

    @Bean
    @Qualifier("identifier3")
    public Endpoint endpoint3() {
        // 参数二，是SEI实现类对象
        EndpointImpl endpoint = new EndpointImpl(this.springBus(), this.cqbcWebservice());
        // 发布服务
        endpoint.publish("/CqbcWebservice");
        return endpoint;
    }

}
